Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement package.json's imports field #4895

Merged
merged 14 commits into from
May 18, 2023
Merged

Implement package.json's imports field #4895

merged 14 commits into from
May 18, 2023

Conversation

jridgewell
Copy link
Contributor

@jridgewell jridgewell commented May 11, 2023

Description

The imports field is similar to exports. While exports allows a package to control how others can import it, imports allows it control how it wants to import other packages.

The majority of the code can be shared with the already-implemented ExportsField and AliasMap, with just special parsing logic. Besides that, I just needed to setup the conditional for imports and some cleanup.

Testing Instructions

RUST_BACKTRACE=1 cargo nextest run -E 'test(snapshot__imports__subpath_imports)'

Fixes WEB-50
Pair: vercel/next.js#49636
fix #4799

@jridgewell jridgewell requested a review from a team as a code owner May 11, 2023 00:48
@vercel
Copy link

vercel bot commented May 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-native-web 🔄 Building (Inspect) Visit Preview May 18, 2023 9:40pm
10 Ignored Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-cra-web ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-nonmonorepo ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm
turbo-site ⬜️ Ignored (Inspect) Visit Preview May 18, 2023 9:40pm

@socket-security
Copy link

socket-security bot commented May 11, 2023

No dependency changes detected. Learn more about Socket for GitHub ↗︎


👍 No new dependency issues detected in pull request

Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore [email protected] bar@* or ignore all packages with @SocketSecurity ignore-all

Pull request alert summary
Issue Status
Install scripts ✅ 0 issues
Native code ✅ 0 issues
Bin script shell injection ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues

@github-actions
Copy link
Contributor

✅ This change can build next-swc

@github-actions
Copy link
Contributor

github-actions bot commented May 11, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Turbopack Rust tests (mac/win, non-blocking)

See workflow summary for details

}
}

fn try_from(value: &Value, ty: ExportImport) -> Result<Self> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to reuse SubpathValue parsing for imports, I needed to pass an additional ExportImport type to print the correct error messages. That prevents us from reusing the TryFrom trait. The code is otherwise the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried about the name.
I think someone may expect SubpathValue::try_from to be one from TryFrom, and to use v.try_into()?.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to try_new

@@ -115,6 +115,53 @@ async fn base_resolve_options(
let mut plugins = opt.plugins.clone();
plugins.push(UnsupportedSassResolvePluginVc::new(root).as_resolve_plugin());

let conditions = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hoisted so that it can be shared for both "into" and "in" conditions. No changes.

@github-actions
Copy link
Contributor

Linux Benchmark for bd92efb

Test Base PR % Significant %
bench_startup/Turbopack CSR/1000 modules 944.09ms ± 6.63ms 964.71ms ± 3.23ms +2.18% +0.09%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8591.41µs ± 37.85µs 8477.49µs ± 39.08µs -1.33%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7886.46µs ± 66.78µs 7910.82µs ± 61.52µs +0.31%
bench_startup/Turbopack CSR/1000 modules 944.09ms ± 6.63ms 964.71ms ± 3.23ms +2.18% +0.09%

@github-actions
Copy link
Contributor

MacOS Benchmark for bd92efb

Test Base PR % Significant %
bench_hmr_to_eval/Turbopack CSR/1000 modules 24.66ms ± 0.39ms 51.56ms ± 5.79ms +109.11% +57.18%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 25.84ms ± 0.14ms 26.20ms ± 0.26ms +1.40%
bench_hmr_to_eval/Turbopack CSR/1000 modules 24.66ms ± 0.39ms 51.56ms ± 5.79ms +109.11% +57.18%
bench_startup/Turbopack CSR/1000 modules 2780.35ms ± 48.67ms 2628.91ms ± 31.71ms -5.45%

@jridgewell jridgewell requested a review from alexkirsz May 16, 2023 18:28
@jridgewell jridgewell added the pr: automerge Kodiak will merge these automatically after checks pass label May 16, 2023
@github-actions
Copy link
Contributor

Linux Benchmark for 527498c

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 4632.70µs ± 18.38µs 4586.13µs ± 39.52µs -1.01%
bench_hmr_to_eval/Turbopack CSR/1000 modules 4265.50µs ± 25.21µs 4491.44µs ± 294.86µs +5.30%
bench_startup/Turbopack CSR/1000 modules 701.01ms ± 1.05ms 708.14ms ± 4.47ms +1.02%

@kodiakhq kodiakhq bot merged commit e3a5cfb into main May 18, 2023
@kodiakhq kodiakhq bot deleted the jrl-imports branch May 18, 2023 22:13
jridgewell added a commit to vercel/next.js that referenced this pull request May 18, 2023
@github-actions
Copy link
Contributor

MacOS Benchmark for 527498c

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 27.32ms ± 0.20ms 26.50ms ± 0.15ms -3.00% -0.45%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 27.32ms ± 0.20ms 26.50ms ± 0.15ms -3.00% -0.45%
bench_hmr_to_eval/Turbopack CSR/1000 modules 25.68ms ± 0.11ms 25.45ms ± 0.15ms -0.89%
bench_startup/Turbopack CSR/1000 modules 2453.49ms ± 16.77ms 2498.73ms ± 43.88ms +1.84%

sokra added a commit to vercel/next.js that referenced this pull request May 19, 2023
vercel/turborepo#4895 renamed `ExportsValue` into
`SubpathValue`

---------

Co-authored-by: Tobias Koppers <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
hydRAnger pushed a commit to hydRAnger/next.js that referenced this pull request Jun 12, 2023
vercel/turborepo#4895 renamed `ExportsValue` into
`SubpathValue`

---------

Co-authored-by: Tobias Koppers <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
### Description

The [imports field](https://nodejs.org/api/packages.html#imports) is
similar to `exports`. While `exports` allows a package to control how
others can import it, `imports` allows it control how it wants to import
other packages.

The majority of the code can be shared with the already-implemented
`ExportsField` and `AliasMap`, with just special parsing logic. Besides
that, I just needed to setup the conditional for imports and some
cleanup.

### Testing Instructions

```bash
RUST_BACKTRACE=1 cargo nextest run -E 'test(snapshot__imports__subpath_imports)'
```

Fixes WEB-50
Pair: #49636
fix vercel/turborepo#4799

---------

Co-authored-by: Tobias Koppers <[email protected]>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

The [imports field](https://nodejs.org/api/packages.html#imports) is
similar to `exports`. While `exports` allows a package to control how
others can import it, `imports` allows it control how it wants to import
other packages.

The majority of the code can be shared with the already-implemented
`ExportsField` and `AliasMap`, with just special parsing logic. Besides
that, I just needed to setup the conditional for imports and some
cleanup.

### Testing Instructions

```bash
RUST_BACKTRACE=1 cargo nextest run -E 'test(snapshot__imports__subpath_imports)'
```

Fixes WEB-50
Pair: #49636
fix vercel/turborepo#4799

---------

Co-authored-by: Tobias Koppers <[email protected]>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
### Description

The [imports field](https://nodejs.org/api/packages.html#imports) is
similar to `exports`. While `exports` allows a package to control how
others can import it, `imports` allows it control how it wants to import
other packages.

The majority of the code can be shared with the already-implemented
`ExportsField` and `AliasMap`, with just special parsing logic. Besides
that, I just needed to setup the conditional for imports and some
cleanup.

### Testing Instructions

```bash
RUST_BACKTRACE=1 cargo nextest run -E 'test(snapshot__imports__subpath_imports)'
```

Fixes WEB-50
Pair: #49636
fix vercel/turborepo#4799

---------

Co-authored-by: Tobias Koppers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: automerge Kodiak will merge these automatically after checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WEB-50] Support package.json imports field
5 participants